<template>
	<view>
		<view class="box">
			<view class="menu_content_box_page">
				<view class="pa15">
					<view class="mt15 area_block_1" v-for="item, index in recruimentList" v-if="recruimentList.length > 0">
						<view class="flex_box aic">
							<view class="item" @tap="toDetail(item.id)">
								<view class="re mr25 fs32 lh44">{{item.title}}</view>
								<view class="mt15 flex_box aic">
									<view class="df aic">
										<image :lazy-load="true"  src="/static/icon_location.png" class="vt img3"></image>
										<view class="ml5 fs26 cor_808">{{item.place}}</view>
									</view>
									<view class="item tar fs30 fwb cor_F23"><text
											class="fs32">￥{{item.salary}}</text>/小时</view>
								</view>
							</view>
							<!-- 删除-按钮 -->
							<view class="ml25 delete_btn" @tap.stop="del(item.id)">删除</view>
						</view>
					</view>


					<view v-if="recruimentList.length == 0" style="width: 100%;height: 100vh">
						<view style="height: 200rpx;"></view>
						<image :lazy-load="true"  src="../../static/excavator.png" style="width: 100%; padding: 100rpx 200rpx;">
						</image>
						<view style="width: 100%;text-align: center;color: #808080;">暂无数据</view>
					</view>



				</view>
			</view>
			<!-- 添加-按钮 -->
			<view class="consult_immediately_btn" @tap="add">添加</view>
		</view><!-- box -->
	</view>
</template>

<script>
	import {
		toast,
		showLoading,
		hideLoading
	} from '@/utils/toast.js';
	import {
		getMyRecruitsApi,
		deleteRecruitApi
	} from '@/http/api.js';
	export default {
		data() {
			return {
				recruimentList: [],
				pageIndex: 1,
				pageSize: 10,
				totalPage: 0,
				userId: uni.getStorageSync('userId')
			}
		},
		onLoad() {
			this.userId = uni.getStorageSync('userId');
			this.getMyRecruits();
		},
		onBackPress(options) {
		    uni.redirectTo({
		    	url: '/pages/personal_center/personal_center'
		    })
			return true;
		},
		methods: {
			getMyRecruits() {
				let that = this;
				showLoading('加载中');
				getMyRecruitsApi({
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
					userId: this.userId
				}).then(res => {
					this.pageIndex = res.data.currentPage;
					this.totalPage = res.data.totalPage;
					this.beginPage = res.data.beginPage;
					if (that.pageIndex == 1) {
						that.recruimentList = res.data.data;
					} else {
						for (let i in res.data) {
							that.recruimentList.push(res.data[i])
						}
					}
					hideLoading();
				}).catch(err => {
					hideLoading();
				})
			},

			del(id) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除吗？',
					success: function(res) {
						if (res.confirm) {
							showLoading('加载中');
							deleteRecruitApi({
								id: id
							}).then(result => {
								that.getMyRecruits();
							}).catch(error => {
								hideLoading();
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},

			add() {
				uni.navigateTo({
					url: '/pages/fill_recruitment_Information/fill_recruitment_Information'
				})
			},

			toDetail(id) {
				uni.navigateTo({
					url: '/pages/edit_recruitment_Information/edit_recruitment_Information?id=' + id
				})
			}
		}
	}
</script>

<style>
	.menu_content_box_page {
		position: relative;
		height: 100vh;
		padding-bottom: 98rpx;
		background-color: #f7f6f6;
	}

	.area_block_1 {
		position: relative;
		padding: 32rpx 20rpx;
		background-color: #fff;
		border-radius: 20rpx;
	}

	.watermark_img_pos {
		position: absolute;
		top: 86rpx;
		right: 20rpx;
		width: 92rpx;
		height: 92rpx;
		z-index: 2;
	}

	.delete_btn {
		display: inline-block;
		width: 125rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		font-size: 30rpx;
		color: #fff;
		text-align: center;
		background-image: linear-gradient(90deg, #f46933, #e3140b);
		border-radius: 40rpx;
	}

	.consult_immediately_btn {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		display: block;
		height: 98rpx;
		line-height: 98rpx;
		text-align: center;
		font-size: 34rpx;
		font-weight: bold;
		color: #fff;
		background: linear-gradient(90deg, #f44f33, #e10d09);
		z-index: 3;
	}
</style>
